﻿using log4net;
using log4net.Config;
using Newtonsoft.Json;
using System;

namespace utils
{
    public static class ApiLog
    {

        private static readonly ILog DebugLogger = LogManager.GetLogger("iHealth.DEBUG");
        private static readonly ILog InfoLogger = LogManager.GetLogger("iHealth.Info");
        private static readonly ILog ErrorLogger = LogManager.GetLogger("iHealth.ERROR");

        static ApiLog()
        {
            XmlConfigurator.Configure();
        }

        public static void Fatal(object message)
        {
            ErrorLogger.Error(message);
        }

        public static void FatalFormat(string format, params object[] args)
        {
            ErrorLogger.ErrorFormat(format, args);
        }

        public static void Fatal(object message, Exception exception)
        {
            ErrorLogger.Error(message, exception);
        }

        public static void Error(object message)
        {
            ErrorLogger.Error(message);
        }

        public static void ErrorFormat(string format, params object[] args)
        {
            ErrorLogger.ErrorFormat(format, args);
        }

        public static void Error(object message, Exception exception)
        {
            ErrorLogger.Error(message, exception);
        }

        public static void Warn(object message)
        {
            ErrorLogger.Warn(message);
        }

        public static void WarnFormat(string format, params object[] args)
        {
            ErrorLogger.WarnFormat(format, args);
        }

        public static void Warn(object message, Exception exception)
        {
            ErrorLogger.Warn(message, exception);
        }

        public static void Info(object message)
        {
            InfoLogger.Info(message);
        }

        public static void InfoFormat(string format, params object[] args)
        {
            InfoLogger.InfoFormat(format, args);
        }

        public static void Info(object message, Exception exception)
        {
            InfoLogger.Info(message, exception);
        }

        public static void Debug(object message)
        {
            DebugLogger.Debug(message);
        }

        public static void DebugFormat(string format, params object[] args)
        {
            DebugLogger.DebugFormat(format, args);
        }

        public static string JsonConvertHelper(object entity)
        {
            string str = "null";
            if (entity != null)
            {
                str = JsonConvert.SerializeObject(entity);
            }
            return str;
        }
    }
}
